/**
 * 打印工具类
 */

import { hiprint } from 'vue-plugin-hiprint'
// 自定义打印元素
export const provider1 = function (options) {
  var addElementTypes = function (context) {
    context.removePrintElementTypes('providerModule1')
    context.addPrintElementTypes('providerModule1', [
      new hiprint.PrintElementTypeGroup('常规', [
        options.config,
        {
          tid: 'providerModule1.header',
          title: '单据表头',
          data: '单据表头',
          type: 'text',
          options: {
            field: "table",
            fields: [
              { text: "名称", field: "NAME" },
              { text: "数量", field: "SL" },
              { text: "规格", field: "GG" },
              { text: "条码", field: "TM" },
              { text: "单价", field: "DJ" },
              { text: "金额", field: "JE" },
              { text: "备注", field: "DETAIL" },
            ],
          },
          columns: [
            [
              { title: "名称", align: "center", field: "NAME", width: 100 },
              { title: "数量", align: "center", field: "SL", width: 100 },
              { title: "条码", align: "center", field: "TM", width: 100 },
              { title: "规格", align: "center", field: "GG", width: 100 },
              { title: "单价", align: "center", field: "DJ", width: 100 },
              { title: "金额", align: "center", field: "JE", width: 100 },
              { title: "备注", align: "center", field: "DETAIL", width: 100 },
            ],
          ],
          footerFormatter: function (options, rows, data, currentPageGridRowsData) {
            console.log(currentPageGridRowsData);
            if (data && data["totalCap"]) {
              return `<td style="padding:0 10px" colspan="100">${"应收金额大写: " + data["totalCap"]}</td>`;
            }
            return '<td style="padding:0 10px" colspan="100">应收金额大写: </td>';
          },
        },
        {
          tid: 'providerModule1.type',
          title: '单据类型',
          data: '单据类型',
          type: 'text',
          options: {
            testData: '单据类型',
            height: 16,
            fontSize: 15,
            fontWeight: '700',
            textAlign: 'center',
            hideTitle: true
          }
        },
        {
          tid: 'providerModule1.order',
          title: '订单编号',
          data: 'XS888888888',
          type: 'text',
          options: {
            field: 'order',
            testData: 'XS888888888',
            height: 16,
            fontSize: 6.75,
            fontWeight: '700',
            textAlign: 'left',
            textContentVerticalAlign: 'middle'
          }
        },
        {
          tid: 'providerModule1.date',
          title: '业务日期',
          data: '2020-01-01',
          type: 'text',
          options: {
            field: 'date',
            testData: '2020-01-01',
            height: 16,
            fontSize: 6.75,
            fontWeight: '700',
            textAlign: 'left',
            textContentVerticalAlign: 'middle'
          }
        },
        {
          tid: 'providerModule1.barcode',
          title: '条形码',
          data: 'XS888888888',
          type: 'text',
          options: {
            field: 'barcode',
            testData: 'XS888888888',
            height: 32,
            fontSize: 12,
            lineHeight: 18,
            textAlign: 'left',
            textType: 'barcode'
          }
        },
        {
          tid: "providerModule1.qrcode",
          title: "二维码",
          data: "XS888888888",
          type: "text",
          options: {
            field: "qrcode",
            testData: "XS888888888",
            height: 32,
            fontSize: 12,
            lineHeight: 18,
            textType: "qrcode",
          },
        },
        {
          tid: 'providerModule1.platform',
          title: '平台名称',
          data: '平台名称',
          type: 'text',
          options: {
            field: 'platform',
            testData: '平台名称',
            height: 17,
            fontSize: 16.5,
            fontWeight: '700',
            textAlign: 'center',
            hideTitle: true
          }
        },
        { tid: 'providerModule1.image', title: 'Logo', data: '', type: 'image', options: { field: 'image', src: 'http://localhost:9528/img/EsunLogo.png', height: 40, width: 147, textAlign: 'center', hideTitle: true }}
      ]),
      new hiprint.PrintElementTypeGroup('客户', [
        {
          tid: 'providerModule1.khname',
          title: '客户名称',
          data: '高级客户',
          type: 'text',
          options: {
            field: 'name',
            testData: '高级客户',
            height: 16,
            fontSize: 6.75,
            fontWeight: '700',
            textAlign: 'left',
            textContentVerticalAlign: 'middle'
          }
        },
        {
          tid: 'providerModule1.tel',
          title: '客户电话',
          data: '18888888888',
          type: 'text',
          options: {
            field: 'tel',
            testData: '18888888888',
            height: 16,
            fontSize: 6.75,
            fontWeight: '700',
            textAlign: 'left',
            textContentVerticalAlign: 'middle'
          }
        }
      ])
    ])
  }
  return {
    addElementTypes: addElementTypes
  }
}
